package com.estate.business.impl;

import java.util.Date;
import java.util.List;

import com.estate.business.TenderService;
import com.estate.dao.TenderDao;
import com.estate.utils.DeleProjectUtil;
import com.estate.vo.Vo;
import com.estate.vo.impl.DeleProjectVo;
import com.estate.vo.impl.TenderVo;

public class TenderServiceImpl implements TenderService {

	private TenderDao tenderDao;

	public TenderDao getTenderDao() {
		return tenderDao;
	}

	public void setTenderDao(TenderDao tenderDao) {
		this.tenderDao = tenderDao;
	}
	
	public boolean addTender(TenderVo tender) {
		boolean result =false; 
		result = this.getTenderDao().addVo(tender);
		return result;
	}

	public List<Vo> getList(){
		List<Vo> allList = this.getTenderDao().findAll();
		return allList;
	}

	public TenderVo getTender(int id){
		TenderVo project = (TenderVo) this.getTenderDao().findByPK(id);
		return project;
	}

	public boolean updateTender(TenderVo tender) {
		boolean result =false;
		TenderVo old = this.getTender(tender.getId());
		tender.setPostDate(old.getPostDate());
		
		tender.setPostUser(old.getPostUser());
		tender.setPro(old.getPro());
		
		result = this.getTenderDao().updateVo(tender);
		return true;
	}
	
	
	public boolean deleteMultiTender(String delStr){
		if(delStr!= null && !"".equals(delStr) && !",".equals(delStr)){
			String[] delArray = delStr.split(",");
			TenderVo tender = null;
			for(int i = 0;i<delArray.length;i++){
				tender = new TenderVo();
				tender.setId(Integer.parseInt(delArray[i]));
				this.deleteTender(tender);
			}
		}
		return true;
	}
	
	public boolean deleteTender(TenderVo tender){
		boolean result = false;
		result = this.getTenderDao().deleteVo(tender);
		return result;
	}
}
